package com.epam.kulibaba.components.productDescription;

import java.util.HashMap;
import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.testng.Reporter;

import com.epam.kulibaba.components.Component;

public class ProductDescription extends Component {
	public static final String ITEMDESCRIPTION = ".panel.corner.item-stats";
	
	
	@FindBy(css = ProductDescription.ITEMDESCRIPTION)
	private WebElement itemDescription;	
	

	public WebElement getItemDescription() {
		return itemDescription;
	}	
	
	public  ProductDescription getProductDescription(WebDriver driver) {
		ProductDescription productDescription = PageFactory.initElements(driver,
				ProductDescription.class);		
		return productDescription;
	}
	
	public static HashMap<String, String> getDescription(
			ProductDescription productDescription) {
		Reporter.log("Get product description on product page");
		HashMap<String, String> productDescriptions = new HashMap<String, String>();
		List<WebElement> rowDescriptions = productDescription
				.getItemDescription().findElements(By.cssSelector("div.row"));
		for (WebElement row : rowDescriptions) {
			String name = row.findElement(By.cssSelector("span.pr")).getText()
					.toLowerCase();
			String value = row.findElement(By.cssSelector("span.val"))
					.getText().toLowerCase();
			productDescriptions.put(name, value);
		}
		
		/*for (Map.Entry me : productDescriptions.entrySet()) {
		 System.out.println(me.getKey() + " " + me.getValue()); }*/
		 
		return productDescriptions;
	}
}
